﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;
using System.IO;
using TcpIpNet;

namespace TestMySqlConnetPoll
{
    /// <summary>
    /// 网络通信协议包结构
    /// </summary>
    public struct objProtecol
    {
        public int lenght;     //长度
        public int Flag;       //标志
        public List<byte> Data;    //数据集合
    }
    static public class c_NetCom
    {
        ///全局变量
        public static TcpClient TcpConnect;
        #region zlib引用
        //压缩zlib常量:
        public const int Z_NO_FLUSH = 0;
        public const int Z_PARTIAL_FLUSH = 1; /* 将要被删除, 使用Z_SYNC_FLUSH 代替他们 */
        public const int Z_SYNC_FLUSH = 2;
        public const int Z_FULL_FLUSH = 3;
        public const int Z_FINISH = 4; /* Allowed flush values ; see deflate() below for details */
        public const int Z_OK = 0;
        public const int Z_STREAM_END = 1;
        public const int Z_NEED_DICT = 2;
        public const int Z_ERRNO = -1;
        public const int Z_STREAM_ERROR = -2;
        public const int Z_DATA_ERROR = -3;
        public const int Z_MEM_ERROR = -4;
        public const int Z_BUF_ERROR = -5;
        public const int Z_VERSION_ERROR = -6; /* 压缩/解压缩的返回值.负值是错误,正值是特殊但是正常的值. */
        public const int Z_NO_COMPRESSION = 0;
        public const int Z_BEST_SPEED = 1;
        public const int Z_BEST_COMPRESSION = 9;
        public const int Z_DEFAULT_COMPRESSION = -1; /* 压缩级别 */
        public const int Z_FILTERED = 1;
        public const int Z_HUFFMAN_ONLY = 2;
        public const int Z_DEFAULT_STRATEGY = 0; /* 压缩策略; see deflateInit2() below for details */
        public const int Z_BINARY = 0;
        public const int Z_ASCII = 1;
        public const int Z_UNKNOWN = 2; /* Possible values of the data_type field */
        public const int Z_DEFLATED = 8;/* The deflate compression method (the only one supported in this version) */
        public const int Z_NULL = 0; /* 用于初始化zalloc, zfree, opaque */

        /// <summary>
        /// 内存压缩
        /// </summary>
        /// <param name="SourceLength"></param>
        /// <returns></returns>
        [DllImport("zlib1.dll", EntryPoint = "gzopen", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        ///  //使用原长度，计算压缩后的长度
        public static extern ulong compressBound(UInt64 SourceLength);  //使用原长度，计算压缩后的长度
        [DllImport("zlib1.dll", EntryPoint = "compress", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        public static extern int compress(byte[] destBuf, ref int destLength, byte[] sourceBuf, int sourceLength);
        [DllImport("zlib1.dll", EntryPoint = "uncompress", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        public static extern int uncompress(byte[] destBuf, ref int destLength, byte[] sourceBuf, int sourceLength);

        /// <summary>
        /// 文件压缩
        /// 文件压缩步骤：1.把压缩的源文件加入到内存中，2.gzopen打开一个文件，相当于创建一个临时文件，该文件名不能重名；2.gzwrite把要压缩的的数据写入到第2步的文件中。        /// 
        ///              3.gzclose关闭文件，3.使用普通文件打开方式，读取数据后再发送。4.发送完成后，关闭文件，删除临时文件。
        ///              
        /// 文件解压缩步骤：1.从网络上收到数据，使用普通文件打开方式，把该数据写入临时文件，关闭该文件，2.使用gzopen打开该文件，使用gzread读取文件内容到内存中。
        ///              3.gzclose关闭文件，删除临时文件。
        /// </summary>
        [DllImport("zlib1.dll", EntryPoint = "gzopen", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        public static extern IntPtr gzopen(string filePath, string mode);
        [DllImport("zlib1.dll", EntryPoint = "gzwrite", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        public static extern int gzwrite(IntPtr handle, byte[] buf, uint len);
        [DllImport("zlib1.dll", EntryPoint = "gzread", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        public static extern int gzread(IntPtr handle, byte[] buf, uint len);
        [DllImport("zlib1.dll", EntryPoint = "gzclose", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        public static extern bool gzclose(IntPtr handle);
        #endregion
        /// <summary>
        /// 文件压缩
        /// </summary>
        /// <param name="sourceBuf"></param>    //源数据保持的缓冲区
        /// <param name="sourceLen"></param>    //源数据长度
        /// <param name="destBuf"></param>      //输出的目标数据缓冲区
        /// <param name="destLen"></param>      //输出的目标数据长度
        /// <param name="Flag"></param>         //压缩方式，内存压缩=1，文件压缩 = 0
        /// <returns></returns>
        public static int zCompress(byte[]sourceBuf,int sourceLen, byte[] destBuf, ref int destLen, byte Flag)
        {
            if (Flag == 1)  //内存压缩
            {
                try
                {
                    return compress(destBuf, ref destLen, sourceBuf, sourceLen);
                }
                catch
                {
                    Console.WriteLine("内存压缩出错");
                }
            }
            else            //文件压缩
            {
                string tmpFilePath = System.Environment.CurrentDirectory;
                string randomstr = DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();
                tmpFilePath += "\\zc" + randomstr;
                try
                {
                    IntPtr handle = gzopen(tmpFilePath, "wb");
                    if (handle != null) //文件建立成功
                    {
                        int ret = gzwrite(handle, sourceBuf, (uint)sourceLen);
                        if (ret != sourceLen)   //写入字节数不对，失败
                        {
                            gzclose(handle);
                            Console.WriteLine("gzwrite写入字节数不对");
                            return -1;
                        }
                        gzclose(handle);    //压缩文件写入成功，需要把压缩后的数据读到内存中.
                        FileStream fs = new FileStream(tmpFilePath, FileMode.Open, FileAccess.Read);
                        long fileLen = fs.Length;
                        if (fileLen > destLen)
                        {
                            Console.WriteLine("目标缓冲区长度不够");
                            fs.Close();
                            File.Delete(tmpFilePath);   //删除文件
                            return -1;
                        }
                        else
                        {
                            destLen = fs.Read(destBuf, 0, (int)fileLen);
                            if (destLen == fileLen)
                            {
                                fs.Close();
                                File.Delete(tmpFilePath);   //删除文件
                                return 0;   //读取成功
                            }
                        }
                    }
                    else  //文件打开失败
                    {
                        Console.WriteLine("gzwrite文件打开失败");
                        return -1;
                    }
                }
                catch
                {
                    Console.WriteLine("文件压缩出错");
                }
            }
            return -1;
        }

        public static int zUNcompress(byte[] sourceBuf, int sourceLen, byte[] destBuf, ref int destLen, byte Flag)
        {
            if (Flag == 1)
            {
                try
                {
                    return uncompress(destBuf, ref destLen, sourceBuf, sourceLen);
                }
                catch
                {
                    Console.WriteLine("内存解压缩出错");
                }
            }
            else
            {
                string tmpFilePath = System.Environment.CurrentDirectory;
                string randomstr = DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();
                tmpFilePath += "\\zu" + randomstr;
                try
                {
                    //首先把压缩的数据写入到文件中
                    FileStream fs = new FileStream(tmpFilePath, FileMode.CreateNew, FileAccess.Write);
                    fs.Write(sourceBuf, 0, sourceLen);
                    fs.Close();
                    //再使用压缩打开方式
                    IntPtr handle = gzopen(tmpFilePath, "rb");
                    if (handle != null)
                    {
                        destLen = gzread(handle, destBuf, (uint)destLen);
                        gzclose(handle);
                        File.Delete(tmpFilePath);
                        return 0;
                    }
                    else
                    {
                        Console.WriteLine("gzopen出错");
                    }
                }
                catch
                {
                    Console.WriteLine("文件解压缩出错");
                }
            }
            return -1;
        }

        /// <summary>
        /// 主动上送开关量定时器
        /// </summary>
        private static System.Timers.Timer time_AutoSendAllKGL = new System.Timers.Timer();

        //private static System.Timers.Timer time_AutoSendLkRt = new System.Timers.Timer(); //C2以下列控使用，暂时未开放

        private static int KglSendTick = 1; //开关量完整性编号 

        private static Thread Thread_NetCom;
        private static bool NetComRum = true;

        public static event EventHandler Event_OneNetComData;

        /// <summary>
        /// 网络上电报码集合
        /// </summary>
        //static public List<string> NetTelexCodeDset = new List<string>();
        /// <summary>
        /// 从网络接收到的数据，没有判断头尾的数据
        /// </summary>
        static private Queue<List<byte>> JudgeDataQueue = new Queue<List<byte>>();
        //static public List<byte> NetComRevData = new List<byte>();
        /// <summary>
        /// 已经整理好的网络网络数据
        /// </summary>
        static public Queue<objProtecol> TidyNetProteclQueue = new Queue<objProtecol>();
        /// <summary>
        /// 检查电报码是否有效
        /// </summary>
        /// <param name="Code"></param>
        /// <returns></returns>
        static public bool ValidTelexCode(string Code)
        {
            //if (NetTelexCodeDset.Contains(Code)) return true;
            if (Code == c_Config.sysConfig.TelexCode) return true;
            if (Code == c_Config.sysConfig.SevTelexCode) return true;
            return false;
        }

        /// <summary>
        /// 初始化实时上送数据定时器
        /// </summary>
        public static void InitNetCom()
        {
            time_AutoSendAllKGL.Elapsed += new System.Timers.ElapsedEventHandler(AutoSendAllKGL_Elapsed);
            time_AutoSendAllKGL.AutoReset = true;
            time_AutoSendAllKGL.Interval = 1000*60;
            time_AutoSendAllKGL.Enabled = true;

            TcpConnect = new TcpClient(c_Config.sysConfig.SevIpAddress, c_Config.sysConfig.SevPort, 5 * 1000 * 60);
            TcpConnect.Event_RevTcpData += new EventHandler(TcpConnect_Event_RevTcpData);

            Thread_NetCom = new Thread(new ThreadStart(Thread_DisposeNetData));

        }
        /// <summary>
        /// 开关量1s上送数据定时器
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="e"></param>
        private static void AutoSendAllKGL_Elapsed(object obj, System.Timers.ElapsedEventArgs e)
        {
            AutoSendKGLALLRealTimeData();
        }

        static public void Stop_Thread_DisposeNetData()
        {
            NetComRum = false;
        }

        static private void Thread_DisposeNetData()
        {
            List<byte> tb = new List<byte>();
            while (NetComRum)
            {
                if (Monitor.TryEnter(JudgeDataQueue, 500))
                {
                    while (JudgeDataQueue.Count > 0)
                    {
                        List<byte> t = JudgeDataQueue.Dequeue();   //从网络缓冲区中取数据;
                        tb.AddRange(t);
                    }
                    Monitor.Exit(JudgeDataQueue);
                }
                if (tb.Count >= 16)           //最短数据包为心跳帧，共16字节
                {
                    byte[] SourceBuf = tb.ToArray();
                    tb.Clear();     //清除原始缓冲区
                    int m = 0;  //偏移量
                    while (true)
                    {
                        byte[] JudgeBuf = new byte[SourceBuf.Length];   //判断同步的偏移缓冲区，实际用于判断的缓冲区
                        Array.Copy(SourceBuf, m, JudgeBuf, 0, SourceBuf.Length - m);
                        if (JudgeBuf.Length >= 16)
                        {
                            int Flag = tb[4];
                            if (Flag == 0x8f || Flag == 0x0f)
                            {
                                byte[] Scode = new byte[3];
                                Array.Copy(JudgeBuf, 5, Scode, 0, 3);   //第5个字节开始为目的电报码
                                string Sscode = System.Text.UTF8Encoding.UTF8.GetString(Scode);
                                byte[] Dcode = new byte[3];
                                Array.Copy(JudgeBuf, 8, Dcode, 0, 3);   //第8个字节开始为源电报码
                                string Sdcode = System.Text.UTF8Encoding.UTF8.GetString(Dcode);
                                if (ValidTelexCode(Sscode) /*&& ValidTelexCode(Sdcode)*/)   //站码完全匹配上
                                {
                                    int commandCode = JudgeBuf[11];     //命令和数据标志位
                                    if (commandCode == 0x01 || commandCode == 0)    //标志位正确
                                    {
                                        int protecolVer = 0;
                                        if (commandCode == 0x01) protecolVer = JudgeBuf[12];
                                        else protecolVer = JudgeBuf[13];
                                        if (protecolVer == 0xe0 || protecolVer == 0xe1 || protecolVer == 0xe2)  //协议位正确
                                        {
                                            objProtecol obj = new objProtecol();
                                            byte[] lb = new byte[4];
                                            Array.Copy(JudgeBuf, lb, 4);    //前4个字节为长度
                                            int tmpLen = lb[0] + (lb[1] << 8) + (lb[2] << 16) + (lb[3] << 24);    //整个数据包的长度

                                            if (tmpLen < (JudgeBuf.Length - 5))
                                            {
                                                //没有收完数据，需要继续从网络端口收取数据                                                
                                                tb.AddRange(JudgeBuf);  //把判断好的数据重新加入到list中
                                                break;  //跳出判断，返回收数据.
                                            }
                                            else
                                            {
                                                //判断成功一包数据，放入队列中.
                                                obj.Flag = JudgeBuf[4];     //标志位
                                                obj.lenght = tmpLen;        //数据包的长度.
                                                for (int i = 0; i < tmpLen; i++)
                                                {
                                                    obj.Data.Add(JudgeBuf[5 + i]);
                                                }
                                                //lock (TidyNetProteclQueue) TidyNetProteclQueue.Enqueue(obj);
                                                Event_OneNetComData(obj, new EventArgs());
                                                //剩下的字节数，继续放入原始缓冲区，继续判断                                                
                                                if (JudgeBuf.Length > (tmpLen + 5))
                                                {
                                                    //重新填充SourceBuf判断数据，而不是返回tb进行收数据
                                                    int SurplusLength = JudgeBuf.Length - (tmpLen + 5);
                                                    SourceBuf = new byte[SurplusLength];
                                                    Array.Copy(JudgeBuf, tmpLen + 5, SourceBuf, 0, SurplusLength);
                                                    continue;
                                                }
                                                else
                                                {
                                                    //刚好一帧数据，直接跳出
                                                    break;
                                                }
                                            }
                                        }
                                        else m++;
                                    }
                                    else m++;
                                }
                                else m++; //偏移位继续判断                                
                            }
                            else m++; //偏移位继续判断
                        }
                        else
                        {
                            //保持遗留下来的数据                            
                            tb.AddRange(JudgeBuf);  //把遗留下来的数据加入的最初的缓冲区中
                            break;
                        }
                    }
                }
                else Thread.Sleep(500);     //睡眠500ms，等待网络数据
            }
        }
        /// <summary>
        /// 把从网络收到的数据拆分成协议
        /// 首先判断标志为，如果不为0x8f 和0x0f 则移位数据进行判断
        /// 标志位正确，判断源电报码和目的电报码是否正确，如果正确，再判断数据和命令标志，再判断协议码，如果都正确，则认为该包协议正确。
        /// </summary>
        static public void TcpConnect_Event_RevTcpData(object sender, EventArgs e)
        {
            List<byte> tb = sender as List<byte>;

            if (Monitor.TryEnter(JudgeDataQueue, 500))
            {
                JudgeDataQueue.Enqueue(tb);
                Monitor.Exit(JudgeDataQueue);
            }
        }

        /// <summary>
        /// 组织发送网络数据
        /// </summary>
        /// <param name="flag"></param> 数据帧还是心跳帧
        /// <param name="t"></param> //需要发送的内容
        /// <param name="length"></param>   //需要发送的长度
        /// <returns></returns>
        static public bool SendNetComData(int flag, byte[] t, int length)
        {
            byte[] st = new byte[length + 6];
            int lk = length;        //实际数据的长度
            st[0] = (byte)lk;
            st[1] = (byte)(lk >> 8);
            st[2] = (byte)(lk >> 16);
            st[3] = (byte)(lk >> 24);
            st[4] = (byte)flag;
            Array.Copy(t, 0, st, 5, length);
            bool f = false;
            //f = 网络发送命令;
            return f;
        }
        /// <summary>
        /// 填充电报码信息
        /// </summary>
        /// <param name="st"></param>
        /// <param name="DCode"></param>
        static private void SetTeleCode(byte[] st, string DCode)
        {
            byte[] t = new byte[3];
            t = System.Text.UTF8Encoding.UTF8.GetBytes(DCode);  //目的电报码；
            t.CopyTo(st, 0);    //目的电报码
            c_Config.sysConfig.TelexCodeB.CopyTo(st, 3);    //本机电报码
        }
        /// <summary>
        /// 发送模拟量实时值命令.请求获取同一种设备类型的模拟量数据
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="AnalogType"></param>
        /// <returns></returns>
        static public bool CmdSendOneTypeAnalogRealTimeValue(string DCode, byte AnalogType)
        {
            byte[] st = new byte[11];
            SetTeleCode(st, DCode);
            st[6] = 0x01;
            st[7] = 0xe0;
            st[8] = 0x11;
            st[9] = AnalogType;
            st[10] = 0;         //数据包，命令包，填0
            st[11] = 0xff;
            return SendNetComData(0x0f, st, 12);
        }
        /// <summary>
        /// 发送模拟同一模拟量类型的模拟量数据。
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="AnalogType"></param>
        /// <returns></returns>
        static public bool RetSendOneTypeRealTimeValueData(string DCode, byte AnalogType)
        {
            int MaxLength = 0;
            if (c_RealTimeValue.ReceiveAnalogData.ContainsKey(AnalogType))
            {
                MaxLength = c_RealTimeValue.ReceiveAnalogData[AnalogType].Count * 2 + 100;
            }
            else return false;

            byte[] st = new byte[MaxLength];
            SetTeleCode(st, DCode);
            st[6] = 0x00;
            st[7] = 0x00;   //压缩标志
            st[8] = 0xe0;
            st[9] = 0x11;
            st[10] = AnalogType;
            //以下查找该类模拟量的实时值

            short[] vt = new short[c_RealTimeValue.ReceiveAnalogData[AnalogType].Count];
            c_RealTimeValue.ReceiveAnalogData[AnalogType].CopyTo(vt, 0);
            st[11] = (byte)vt.Length;
            st[12] = (byte)(vt.Length >> 8);    //模拟量个数
            int ntime = (int)MySql.DateTimeToTime_t(DateTime.Now);  //时间以当前时间为准.
            st[13] = (byte)ntime;
            st[14] = (byte)(ntime >> 8);
            st[15] = (byte)(ntime >> 16);
            st[16] = (byte)(ntime >> 24);

            int m = 17;
            for (int i = 0; i < vt.Length; i++) //模拟量值填充
            {
                st[m++] = (byte)(vt[i]);
                st[m++] = (byte)(vt[i] >> 8);
            }
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送提取特定模拟量实时值命令，可以提取多个模拟量。
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="obj"></param>
        /// <param name="Count"></param>
        /// <returns></returns>
        static public bool CmdSendSpecifiedAnalogRealTime(string DCode,List<AnalogObj>obj)
        {
            byte[] st = new byte[obj.Count * 4 + 100];
            SetTeleCode(st, DCode);
            st[6] = 0x01;
            st[7] = 0xe0;
            st[8] = 0x11;
            st[9] = 0xff;   //数据子类型
            st[10] = (byte)obj.Count;   //长度
            st[11] = (byte)(obj.Count >> 8);
            int m = 12;
            for (int i = 0; i < obj.Count; i++)
            {
                int type = (int)obj[i].type;
                st[m++] = (byte)type;
                st[m++] = (byte)(type >> 8);    //类型
                st[m++] = (byte)obj[i].devNo;
                st[m++] = (byte)(obj[i].devNo >> 8);    //序号
            }
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送选定模拟量实时值操作
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="obj"></param>
        /// <param name="Count"></param>
        /// <returns></returns>
        static public bool RetSendSpecifiedAnalogRTData(string DCode, AnalogObj[] obj, int Count)
        {
            byte[] st = new byte[Count * 6 + 100];
            SetTeleCode(st, DCode);
            st[6] = 0x00;
            st[7] = 0x00;   //压缩标志
            st[8] = 0xe0;
            st[9] = 0x11;
            st[10] = 0xff;   //数据子类型
            st[11] = (byte)Count;   //长度
            st[12] = (byte)(Count >> 8);
            int ntime = (int)MySql.DateTimeToTime_t(DateTime.Now);
            st[13] = (byte)ntime;
            st[14] = (byte)(ntime >> 8);
            st[15] = (byte)(ntime >> 16);
            st[16] = (byte)(ntime >> 24);
            int m = 17;
            for (int i = 0; i < Count; i++)
            {
                int type = (int)obj[i].type;
                st[m++] = (byte)type;
                st[m++] = (byte)(type >> 8);
                st[m++] = (byte)obj[i].devNo;
                st[m++] = (byte)(obj[i].devNo >> 8);
                Int16 v = c_RealTimeValue.GetRealTimeAnalogDValue((byte)type, obj[i].devNo);
                st[m++] = (byte)v;
                st[m++] = (byte)(v >> 8);
            }
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送获取模拟量最新值命令，用于绝缘、漏流、残压
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        static public bool CmdSendAnalogNewstValue(string DCode, byte Type)
        {
            byte[] st = new byte[11];
            SetTeleCode(st, DCode);
            st[6] = 0x01;
            st[7] = 0xe0;
            st[8] = 0x12;
            st[9] = Type;
            st[10] = 0;         //数据包，命令包，填0
            st[11] = 0xff;
            return SendNetComData(0x0f, st, 12);
        }
        /// <summary>
        /// 发送绝缘、漏流、残压的最新值，所有值列表
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        static public bool RetSendAnalogNewstValueData(string DCode, byte Type)
        {            
            int count = 0;
            if (Type == 0x80)    //绝缘
            {
                count = c_Device.ZH_AnalogConfig["电缆绝缘"].AnalogList.Count;
            }
            else if (Type == 0x81) //漏流
            {
                count = c_Device.ZH_AnalogConfig["电源漏流"].AnalogList.Count;
            }
            else if (Type == 0x24) //残压
            {
                count = c_Device.GD_AnalogConfig["轨道电压"].AnalogList.Count;
            }
            int MaxSize = count * 6;
            byte[] st = new byte[MaxSize * 6 + 100];
            SetTeleCode(st, DCode);
            st[6] = 0x00;
            st[7] = 0x00;   //压缩标志
            st[8] = 0xe0;
            st[9] = 0x12;
            st[10] = Type;   //数据子类型

            st[11] = (byte)count;
            st[12] = (byte)(count >> 8);
            int m = 13;
            for (short i = 0; i < count; i++)
            {
                objTV obj = c_RealTimeValue.GetJyLlCyRealTimeValue(Type, i);
                st[m++] = (byte)obj.value;
                st[m++] = (byte)(obj.value >> 8);
                st[m++] = (byte)obj.utime;
                st[m++] = (byte)(obj.utime >> 8);
                st[m++] = (byte)(obj.utime >> 16);
                st[m++] = (byte)(obj.utime >> 24);
            }
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 提取日报表时间命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param> //模拟量类型
        /// <returns></returns>
        static public bool CmdSendDailyReportTime(string DCode, byte type)
        { 
            byte[] st = new byte[11];
            SetTeleCode(st, DCode);
            st[6] = 0x01;
            st[7] = 0xe0;
            st[8] = 0x13;
            st[9] = type;
            st[10] = 0x40;         //提取日报表时间命令
            st[11] = 0xff;
            return SendNetComData(0x0f, st, 12);
        }
        /// <summary>
        /// 发送日报表时间列表,没明确日报表时间的格式，是否还是unix时间
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="?"></param>
        /// <returns></returns>
        static public bool RetSendDailyReportTimeData(string DCode, byte type, List<int> li)
        {
            byte[] st = new byte[li.Count * 4 + 100];
            SetTeleCode(st, DCode);
            st[6] = 0x00;
            st[7] = 0x00;   //压缩标志
            st[8] = 0xe0;
            st[9] = 0x13;
            st[10] = type;
            st[11] = 0x40;
            st[12] = (byte)li.Count;
            st[13] = (byte)(li.Count >> 8);
            int m = 14;
            foreach (int v in li)
            {
                st[m++] = (byte)v;
                st[m++] = (byte)(v >> 8);
                st[m++] = (byte)(v >> 16);
                st[m++] = (byte)(v >> 24);
            }
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 提取日报表数据命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="utime"></param>
        /// <returns></returns>
        static public bool CmdSendDailyReportValue(string DCode, byte type, int utime)
        {
            
            byte[] st = new byte[15];
            SetTeleCode(st, DCode);
            st[6] = 0x01;
            st[7] = 0xe0;
            st[8] = 0x13;
            st[9] = type;
            st[10] = 0x41;         //提取日报表数据命令
            st[11] = (byte)utime;
            st[12] = (byte)(utime >> 8);
            st[13] = (byte)(utime >> 16);
            st[14] = (byte)(utime >> 24);
            st[15] = 0xff;
            return SendNetComData(0x0f, st, 16);
        }
        /// <summary>
        /// 发送除绝缘，漏流，残压的日报表
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="utime"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        static public bool RetSendSendDailyReportValueData(string DCode, byte type, int utime, List<objDailyReport> li)
        {
            byte[] st = new byte[li.Count * 18 + 100];
            SetTeleCode(st, DCode);
            st[6] = 0x00;
            st[7] = 0x00;   //压缩标志
            st[8] = 0xe0;
            st[9] = 0x13;
            st[10] = type;
            st[11] = 0x41;
            st[12] = (byte)utime;
            st[13] = (byte)(utime >> 8);
            st[14] = (byte)(utime >> 16);
            st[15] = (byte)(utime >> 24);
            st[16] = (byte)li.Count;
            st[17] = (byte)(li.Count >> 8);
            int m = 18;
            foreach (objDailyReport v in li)
            {
                st[m++] = (byte)v.bMaxValue;
                st[m++] = (byte)(v.bMaxValue >> 8);
                st[m++] = (byte)v.MaxTime;
                st[m++] = (byte)(v.MaxTime >> 8);
                st[m++] = (byte)(v.MaxTime >> 16);
                st[m++] = (byte)(v.MaxTime >> 24);

                st[m++] = (byte)v.bMinValue;
                st[m++] = (byte)(v.bMinValue >> 8);
                st[m++] = (byte)v.MinTime;
                st[m++] = (byte)(v.MinTime >> 8);
                st[m++] = (byte)(v.MinTime >> 16);
                st[m++] = (byte)(v.MinTime >> 24);

                st[m++] = (byte)v.bAvrValue;
                st[m++] = (byte)(v.bAvrValue >> 8);
                st[m++] = (byte)v.AvrTime;
                st[m++] = (byte)(v.AvrTime >> 8);
                st[m++] = (byte)(v.AvrTime >> 16);
                st[m++] = (byte)(v.AvrTime >> 24);
            }
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送日报表，绝缘，漏流，残压的日报表
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="utime"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        static public bool RetSendSendDailyReportValueData(string DCode, byte type, int utime, List<objStruct> li)
        {
            byte[] st = new byte[li.Count * 18 + 100];
            SetTeleCode(st, DCode);
            st[6] = 0x00;
            st[7] = 0x00;   //压缩标志
            st[8] = 0xe0;
            st[9] = 0x13;
            st[10] = type;
            st[11] = 0x41;
            st[12] = (byte)utime;
            st[13] = (byte)(utime >> 8);
            st[14] = (byte)(utime >> 16);
            st[15] = (byte)(utime >> 24);
            st[16] = (byte)li.Count;
            st[17] = (byte)(li.Count >> 8);
            int m = 18;
            foreach (objStruct v in li)
            {
                st[m++] = (byte)v.dValue.Dvalue;
                st[m++] = (byte)(v.dValue.Dvalue >> 8);
                st[m++] = (byte)v.dValue.u_time;
                st[m++] = (byte)(v.dValue.u_time >> 8);
                st[m++] = (byte)(v.dValue.u_time >> 16);
                st[m++] = (byte)(v.dValue.u_time >> 24);
            }
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送提取模拟量日曲线时间列表信息
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        static public bool CmdSendAnalogDailyCurveTime(string DCode, byte type)
        {            
            byte[] st = new byte[11];
            SetTeleCode(st, DCode);
            st[6] = 0x01;
            st[7] = 0xe0;
            st[8] = 0x15;
            st[9] = type;
            st[10] = 0x40;         //提取日报表时间命令
            st[11] = 0xff;
            return SendNetComData(0x8f, st, 12);
        }
        /// <summary>
        /// 发送模拟量日曲线时间回执
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <returns></returns>
        static public bool RetSendAnalogDailyCurveTimeData(string DCode, byte type, int stime, int etime)
        {            
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            st[6] = 0x00;
            st[7] = 0x00;   //压缩标志
            st[8] = 0xe0;
            st[9] = 0x15;
            st[10] = type;
            st[11] = 0x40;
            st[12] = (byte)stime;
            st[13] = (byte)(stime >> 8);
            st[14] = (byte)(stime >> 16);
            st[15] = (byte)(stime >> 24);

            st[16] = (byte)etime;
            st[17] = (byte)(etime >> 8);
            st[18] = (byte)(etime >> 16);
            st[19] = (byte)(etime >> 24);
            st[20] = 0xff;
            return SendNetComData(0x0f, st, 21);
        }
        /// <summary>
        /// 发送提取模拟量日曲线命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="DevNo"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <returns></returns>
        static public bool CmdSendAnalogDailyCurve(string DCode, byte type, Int16 DevNo, int stime, int etime)
        {            
            byte[] st = new byte[21];
            SetTeleCode(st, DCode);
            st[6] = 0x01;
            st[7] = 0xe0;
            st[8] = 0x15;
            st[9] = type;
            st[10] = 0x41;         //提取日报表时间命令
            st[11] = (byte)DevNo;
            st[12] = (byte)(DevNo >> 8);
            st[13] = (byte)stime;
            st[14] = (byte)(stime >> 8);
            st[15] = (byte)(stime >> 16);
            st[16] = (byte)(stime >> 24);

            st[17] = (byte)etime;
            st[18] = (byte)(etime >> 8);
            st[19] = (byte)(etime >> 16);
            st[20] = (byte)(etime >> 24);
            st[21] = 0xff;
            return SendNetComData(0x8f, st, 22);
        }
        /// <summary>
        /// 发送模拟量日曲线数据，
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="DevNo"></param>
        /// <param name="li"></param>li为日曲线数据，为填充为每秒的数据，不在该函数内进行填充
        /// <returns></returns>
        static public bool RetSendAnalogDailyCurveData(string DCode, byte type, Int16 DevNo, List<objTimeValue> li)
        {            
            byte[] st = new byte[li.Count * 6 + 100];
            SetTeleCode(st, DCode);
            st[6] = 0x00;
            st[7] = 0x00;   //压缩标志
            st[8] = 0xe0;
            st[9] = 0x15;
            st[10] = type;
            st[11] = 0x41;
            st[12] = (byte)(DevNo);
            st[13] = (byte)(DevNo >> 8);
            st[14] = (byte)li.Count;
            st[15] = (byte)(li.Count >> 8);
            int m = 16;
            for (int i = 0; i < li.Count; i++)
            {
                st[m++] = (byte)li[i].Dvalue;
                st[m++] = (byte)(li[i].Dvalue >> 8);
                st[m++] = (byte)li[i].u_time;
                st[m++] = (byte)(li[i].u_time >> 8);
                st[m++] = (byte)(li[i].u_time >> 16);
                st[m++] = (byte)(li[i].u_time >> 24);
            }
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 日曲线时间回溯命令,站机发送的
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="num"></param>重复次数
        /// <param name="stime"></param>重复开始时间
        /// <param name="etime"></param>重复结束时间
        /// <returns></returns>
        static public bool RetSendDailyCurveTimeRecallData(string DCode, byte type, int num, int stime, int etime)
        {            
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            st[6] = 0x00;
            st[7] = 0x00;   //压缩标志
            int m = 8;
            st[m++] = 0xe0;
            st[m++] = 0x15;
            st[m++] = type;
            st[m++] = 0x42;         //回溯时间数据
            st[m++] = (byte)num;
            st[m++] = (byte)(num >> 8);
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);

            st[m++] = (byte)etime;
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 回溯时间段命令    模拟量历史曲线数据提取回溯时间段命令信息包
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="devno"></param>
        /// <param name="stime"></param> 开始时间
        /// <param name="etime"></param>结束时间
        /// <param name="recallNum"></param>重复次数
        /// <param name="restime"></param>重复开始时间
        /// <param name="reetime"></param>重复结束时间
        /// <returns></returns>
        static public bool CmdSendAnalogHistoryCurveRecallTime(string DCode, byte type, Int16 devno, int stime, int etime, int recallNum, int restime, int reetime)
        {            
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            st[6] = 0x01;
            int m = 7;
            st[m++] = 0xe0;
            st[m++] = 0x15;
            st[m++] = type;
            st[m++] = 0x42;
            st[m++] = (byte)devno;
            st[m++] = (byte)(devno >> 8);
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);

            st[m++] = (byte)etime;
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);

            st[m++] = (byte)recallNum;
            st[m++] = (byte)(recallNum >> 8);

            st[m++] = (byte)restime;
            st[m++] = (byte)(restime >> 8);
            st[m++] = (byte)(restime >> 16);
            st[m++] = (byte)(restime >> 24);

            st[m++] = (byte)reetime;
            st[m++] = (byte)(reetime >> 8);
            st[m++] = (byte)(reetime >> 16);
            st[m++] = (byte)(reetime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送提取高频曲线命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="devno"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <returns></returns>
        static public bool CmdSendHighFrequencyAnalog(string DCode, byte type, Int16 devno, int stime, int etime)
        {            
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x30;
            st[m++] = type;
            st[m++] = 0x41;
            st[m++] = (byte)devno;
            st[m++] = (byte)(devno >> 8);
            st[m++] = (byte)(stime);
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = (byte)(etime);
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 高频回溯时间命令 站机发送
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="reNum"></param>
        /// <param name="rstime"></param>
        /// <param name="retime"></param>
        /// <returns></returns>
        static public bool RetSendHighFrequencyRecallTime(string DCode, byte type, int reNum, int rstime, int retime)
        {            
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x30;
            st[m++] = type;
            st[m++] = 0x42;
            st[m++] = (byte)reNum;
            st[m++] = (byte)(reNum >> 8);
            st[m++] = (byte)(rstime);
            st[m++] = (byte)(rstime >> 8);
            st[m++] = (byte)(rstime >> 16);
            st[m++] = (byte)(rstime >> 24);
            st[m++] = (byte)(retime);
            st[m++] = (byte)(retime >> 8);
            st[m++] = (byte)(retime >> 16);
            st[m++] = (byte)(retime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送高频模拟量时间段回执，终端收到站机的时间段回执后返回的命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="devno"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <param name="recallNum"></param>
        /// <param name="restime"></param>
        /// <param name="reetime"></param>
        /// <returns></returns>
        static public bool CmdSendHighFrequencyRecallTime(string DCode, byte type, Int16 devno, int stime, int etime, int recallNum, int restime, int reetime)
        {            
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            st[6] = 0x01;
            int m = 7;
            st[m++] = 0xe0;
            st[m++] = 0x30;
            st[m++] = type;
            st[m++] = 0x42;
            st[m++] = (byte)devno;
            st[m++] = (byte)(devno >> 8);
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);

            st[m++] = (byte)etime;
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);

            st[m++] = (byte)recallNum;
            st[m++] = (byte)(recallNum >> 8);

            st[m++] = (byte)restime;
            st[m++] = (byte)(restime >> 8);
            st[m++] = (byte)(restime >> 16);
            st[m++] = (byte)(restime >> 24);

            st[m++] = (byte)reetime;
            st[m++] = (byte)(reetime >> 8);
            st[m++] = (byte)(reetime >> 16);
            st[m++] = (byte)(reetime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }

        /// <summary>
        /// 发送高频模拟量数据，一般指半自闭
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="devno"></param>
        /// <param name="CaiJiF"></param> 采集频率
        /// <param name="li"></param>
        /// <returns></returns>
        static public bool RetSendHighFrequencyAnalogData(string DCode, byte type, Int16 devno, int CaiJiF, List<HigFreAnalogValue> li)
        {            
            byte[] st = new byte[li.Count * 6 + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;   //压缩标志
            st[m++] = 0xe0;
            st[m++] = 0x30;
            st[m++] = type;
            st[m++] = 0x41;
            st[m++] = (byte)(CaiJiF);
            st[m++] = (byte)(CaiJiF >> 8);
            st[m++] = (byte)(devno);
            st[m++] = (byte)(devno >> 8);
            st[m++] = (byte)li.Count;
            st[m++] = (byte)(li.Count >> 8);
            for (int i = 0; i < li.Count; i++)
            {
                int utime = li[i].utime;
                if (CaiJiF != li[i].SecondValueList.Count)  //采集频率和里面的数据个数不相同
                {
                    //报错
                }
                foreach (objHigFre key in li[i].SecondValueList)
                {
                    st[m++] = (byte)key.wValue;
                    st[m++] = (byte)(key.wValue >> 8);
                    st[m++] = (byte)utime;
                    st[m++] = (byte)(utime >> 8);
                    st[m++] = (byte)(utime >> 16);
                    st[m++] = (byte)(utime >> 24);
                }                
            }
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送开关量回放时间命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <returns></returns>
        static public bool CmdSendKGLReplayTime(string DCode)
        {            
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x16;
            st[m++] = 0xff;
            st[m++] = 0x40;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送开关量回放时间范围
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <returns></returns>
        static public bool RetSendKGLReplayTimeData(string DCode, int stime, int etime)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x16;
            st[m++] = 0xff;
            st[m++] = 0x40;
            st[m++] = (byte)(stime);
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = (byte)(etime);
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送提取开关量数据命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <returns></returns>
        static public bool CmdGetKGLReplayData(string DCode, int stime, int etime)
        {            
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x16;
            st[m++] = 0xff;
            st[m++] = 0x41;
            st[m++] = (byte)(stime);
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = (byte)(etime);
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送开关量历史回溯信息,站机
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="reNum"></param>回溯次数
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <returns></returns>
        static public bool RetSendKGLHistoryRecallInfo(string DCode, int reNum, int stime, int etime)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x16;
            st[m++] = 0xff;
            st[m++] = 0x42;
            st[m++] = (byte)reNum;
            st[m++] = (byte)(reNum >> 8);
            st[m++] = (byte)(stime);
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = (byte)(etime);
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送提取开关量回溯时间段数据命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="devno"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <param name="recallNum"></param>
        /// <param name="restime"></param>
        /// <param name="reetime"></param>
        /// <returns></returns>
        static public bool CmdGetKGLRecallData(string DCode, Int16 devno, int stime, int etime, int recallNum, int restime, int reetime)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            st[6] = 0x01;
            int m = 7;
            st[m++] = 0xe0;

            st[m++] = 0x16;
            st[m++] = 0xff;
            st[m++] = 0x42;
            st[m++] = (byte)devno;
            st[m++] = (byte)(devno >> 8);

            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);

            st[m++] = (byte)etime;
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);

            st[m++] = (byte)recallNum;
            st[m++] = (byte)(recallNum >> 8);

            st[m++] = (byte)restime;
            st[m++] = (byte)(restime >> 8);
            st[m++] = (byte)(restime >> 16);
            st[m++] = (byte)(restime >> 24);

            st[m++] = (byte)reetime;
            st[m++] = (byte)(reetime >> 8);
            st[m++] = (byte)(reetime >> 16);
            st[m++] = (byte)(reetime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送开关量回放数据，
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="v"></param>为按照标准通信协议组织好的数据。协议中的数据包内容。
        /// <returns></returns>
        static public bool RetSendKGLReplayData(string DCode, List<byte> v)
        {
            byte[] st = new byte[v.Count + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x16;
            st[m++] = 0xff;
            byte[] vt = v.ToArray();
            Array.Copy(vt, 0, st, m, vt.Length);
            m += vt.Length;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送模拟量回放数据命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <param name="TypeNum"></param> 类型数量，如果为全体模拟量时，为0xff
        /// <param name="Type"></param>模拟量类型集合，让果类型数量 = 0xff, 该项无效
        /// <returns></returns>
        static public bool CmdSendAnalogReplayData(string DCode, int stime, int etime, byte TypeNum, List<byte> Type = null)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x16;
            st[m++] = 0xf0;
            st[m++] = 0x41;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = (byte)etime;
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);
            st[m++] = (byte)TypeNum;
            if (TypeNum != 0xff)
            {
                for (int i = 0; i < Type.Count; i++)
                {
                    st[m++] = Type[i];
                }
            }
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 模拟量回放回溯时间段命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="devNo"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <param name="rNo"></param>   重复序号
        /// <param name="rstime"></param> 重复开始时间
        /// <param name="retime"></param> 重复结束时间
        /// <returns></returns>
        static public bool CmdSendAnalogReplayRecall(string DCode, int devNo, int stime, int etime, int rNo, int rstime, int retime)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x16;
            st[m++] = 0xf0;
            st[m++] = 0x42;
            st[m++] = (byte)devNo;
            st[m++] = (byte)(devNo >> 8);
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = (byte)etime;
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);
            st[m++] = (byte)rNo;
            st[m++] = (byte)(rNo >> 8);
            st[m++] = (byte)rstime;
            st[m++] = (byte)(rstime >> 8);
            st[m++] = (byte)(rstime >> 16);
            st[m++] = (byte)(rstime >> 24);
            st[m++] = (byte)retime;
            st[m++] = (byte)(retime >> 8);
            st[m++] = (byte)(retime >> 16);
            st[m++] = (byte)(retime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 模拟量回放信息
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="ReplayType"></param> 回放类型，普通回放为41H，带回溯功能回放为42H
        /// <param name="stime"></param>开始时间
        /// <param name="li"></param>发送的数据，压缩前数据
        /// <returns></returns>
        static public bool RetSendAnalogReplayData(string DCode, byte ReplayType, int stime, List<byte> li)
        {
            byte[] st = new byte[li.Count+100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00; //文件压缩
            st[m++] = 0xe0;
            st[m++] = 0x16;
            st[m++] = 0xf0;
            st[m++] = ReplayType;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            int destLen = (int)compressBound((UInt64)li.Count); //压缩后的长度
            byte[] destBuf = new byte[destLen];
            int ret = zCompress(li.ToArray(), li.Count, destBuf, ref destLen, 0);   //调用压缩函数，文件压缩
            if (ret == Z_OK)
            {
                st[m++] = (byte)destLen;
                st[m++] = (byte)(destLen >> 8);
                st[m++] = (byte)(destLen >> 16);
                st[m++] = (byte)(destLen >> 24);
                Array.Copy(destBuf, 0, st, m, destLen);
                m += destLen;
                st[m++] = 0xff;
                return SendNetComData(0x0f, st, m);
            }
            return false;
        }
        /// <summary>
        /// 发送高频模拟量回放命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <param name="TypeNum"></param>
        /// <param name="Type"></param>
        /// <returns></returns>
        public static bool CmdSendHighFrequencyReplay(string DCode, int stime, int etime, byte TypeNum, List<byte> Type)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x31;
            st[m++] = 0xf0;
            st[m++] = 0x41;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = (byte)etime;
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);
            st[m++] = (byte)TypeNum;
            if (TypeNum != 0xff)
            {
                for (int i = 0; i < Type.Count; i++)
                {
                    st[m++] = Type[i];
                }
            }
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送高频模拟量回放回溯时间段命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="devNo"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <param name="rNo"></param>
        /// <param name="rstime"></param>
        /// <param name="retime"></param>
        /// <returns></returns>
        public static bool CmdSendHighFrequencyReplayRecall(string DCode, int devNo, int stime, int etime, int rNo, int rstime, int retime)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x31;
            st[m++] = 0xf0;
            st[m++] = 0x42;
            st[m++] = (byte)devNo;
            st[m++] = (byte)(devNo >> 8);
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = (byte)etime;
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);
            st[m++] = (byte)rNo;
            st[m++] = (byte)(rNo >> 8);
            st[m++] = (byte)rstime;
            st[m++] = (byte)(rstime >> 8);
            st[m++] = (byte)(rstime >> 16);
            st[m++] = (byte)(rstime >> 24);
            st[m++] = (byte)retime;
            st[m++] = (byte)(retime >> 8);
            st[m++] = (byte)(retime >> 16);
            st[m++] = (byte)(retime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送高频模拟量回放数据
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="ReplayType"></param>
        /// <param name="stime"></param>
        /// <param name="li"></param>压缩前数据包
        /// <returns></returns>
        public static bool RetSendHighFrequencyReplayData(string DCode, byte ReplayType, int stime, List<byte> li)
        {
            byte[] st = new byte[li.Count+100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00; //文件压缩
            st[m++] = 0xe0;
            st[m++] = 0x31;
            st[m++] = 0xf0;
            st[m++] = ReplayType;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            int destLen = (int)compressBound((UInt64)li.Count); //压缩后的长度
            byte[] destBuf = new byte[destLen];
            int ret = zCompress(li.ToArray(), li.Count, destBuf, ref destLen, 0);   //调用压缩函数，文件压缩
            if (ret == Z_OK)
            {
                st[m++] = (byte)destLen;
                st[m++] = (byte)(destLen >> 8);
                st[m++] = (byte)(destLen >> 16);
                st[m++] = (byte)(destLen >> 24);
                Array.Copy(destBuf, 0, st, m, destLen);
                m += destLen;
                st[m++] = 0xff;
                return SendNetComData(0x0f, st, m);
            }
            return false;
        }
        /// <summary>
        /// 发送全体实时开关量信息
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="kglNum"></param>
        /// <param name="stime"></param>
        /// <param name="Code"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        public static bool AutoSendKGLALLRealTimeData()
        {
            string DCode = c_Config.sysConfig.SevTelexCode;
            int kglNum  = c_RealTimeValue.ReceiveKGLData.kglNum;
            int stime = c_RealTimeValue.ReceiveKGLData.time;
            int Code = KglSendTick++;
            byte[] st = new byte[c_RealTimeValue.ReceiveKGLData.Value.Count+100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x17;
            st[m++] = 0x80;
            st[m++] = (byte)kglNum;
            st[m++] = (byte)(kglNum >> 8);
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);

            Array.Copy(c_RealTimeValue.ReceiveKGLData.Value.ToArray(), 0, st, m, c_RealTimeValue.ReceiveKGLData.Value.Count);
            m += c_RealTimeValue.ReceiveKGLData.Value.Count;

            st[m++] = (byte)Code;
            st[m++] = (byte)(Code >> 8);
            st[m++] = (byte)(Code >> 16);
            st[m++] = (byte)(Code >> 24);

            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送变化开关量实时信息
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="kglNum"></param>
        /// <param name="stime"></param>
        /// <param name="Code"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        public static bool AutoSendkglChangeRealTimeData()
        {
            string DCode = c_Config.sysConfig.SevTelexCode;
            int kglNum = c_RealTimeValue.ReceiveChangeKglData.kglNum;
            int stime = c_RealTimeValue.ReceiveChangeKglData.time;
            int Code = KglSendTick++;
            byte[] st = new byte[c_RealTimeValue.ReceiveChangeKglData.Value.Count + 100];
 
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x17;
            st[m++] = 0x81;
            st[m++] = (byte)kglNum;
            st[m++] = (byte)(kglNum >> 8);
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            
            Array.Copy(c_RealTimeValue.ReceiveChangeKglData.Value.ToArray(), 0, st, m, c_RealTimeValue.ReceiveChangeKglData.Value.Count);
            m += c_RealTimeValue.ReceiveChangeKglData.Value.Count;

            st[m++] = (byte)Code;
            st[m++] = (byte)(Code >> 8);
            st[m++] = (byte)(Code >> 16);
            st[m++] = (byte)(Code >> 24);

            st[m++] = 0xff;

            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送请求全体开关量信息命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <returns></returns>
        public static bool CmdSendRequestKglAll(string DCode)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x17;
            st[m++] = 0x80;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 开关量数据命令信息包
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <returns></returns>
        public static bool CmdSendKglData(string DCode, int stime, int etime)
        {            
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x17;
            st[m++] = 0x82;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = (byte)etime;
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送开关量数据
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="li"></param>按照格式整理好的数据.
        /// <returns></returns>
        public static bool RetSendKglData(string DCode, List<byte> li)
        {
            byte[] st = new byte[li.Count+100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x17;
            st[m++] = 0x82;
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送记录曲线提取时间命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param> 记录曲线类型
        /// <param name="no"></param> 序号
        /// <returns></returns>
        public static bool CmdSendRecordCurveTime(string DCode, byte type, int no)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x18;
            st[m++] = type;
            st[m++] = 0x40;
            st[m++] = (byte)no;
            st[m++] = (byte)(no >> 8);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送记录曲线时间数据
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        public static bool RetSendRecordCurveTime(string DCode, byte type, List<int> li)
        {
            byte[] st = new byte[li.Count+100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x18;
            st[m++] = type;
            st[m++] = 0x40;
            st[m++] = (byte)li.Count;
            st[m++] = (byte)(li.Count >> 8);
            foreach (int v in li)
            {
                st[m++] = (byte)v;
                st[m++] = (byte)(v >> 8);
                st[m++] = (byte)(v >> 16);
                st[m++] = (byte)(v >> 24);
            }
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送提取记录曲线命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="devNo"></param>
        /// <param name="stime"></param>
        /// <returns></returns>
        public static bool CmdSendRecordCurve(string DCode, byte type, int devNo, int stime)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x18;
            st[m++] = type;
            st[m++] = 0x41;
            st[m++] = (byte)devNo;
            st[m++] = (byte)(devNo >> 8);
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送记录曲线数据
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="rNum"></param> 记录个数
        /// <param name="li"></param>
        /// <returns></returns>
        public static bool RetSendRecordCurveData(string DCode, byte type, int rNum, List<byte> li)
        {
            byte[] st = new byte[li.Count + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x18;
            st[m++] = type;
            st[m++] = 0x41;
            st[m++] = (byte)rNum;
            st[m++] = (byte)(rNum >> 8);
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 查询空调参数
        /// </summary>
        /// <param name="DCode"></param>
        /// <returns></returns>
        public static bool CmdSendQueryAirConditionInfo(string DCode)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x33;
            st[m++] = 0x01;
            st[m++] = 0xff;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 站机发送空调数据
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="AirNum"></param>
        /// <param name="li"></param>按照协议组织好的数据
        /// <returns></returns>
        public static bool RetSendAirConditionInfoData(string DCode, int AirNum, List<byte> li)
        {
            byte[] st = new byte[li.Count+100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x33;
            st[m++] = 0x02;
            st[m++] = 0xff;
            st[m++] = (byte)AirNum;
            st[m++] = (byte)(AirNum >> 8);
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 修改空调参数命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="Flag"></param> 修改标志
        /// <param name="stime"></param>
        /// <param name="mode"></param> 修改模式
        /// <param name="updata"></param> 温度下限
        /// <param name="lowdata"></param> 温度上限
        /// <returns></returns>
        static public bool CmdSendAdjustAirCondition(string DCode, byte Flag, int stime, byte mode, int updata, int lowdata)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x33;
            st[m++] = 0x03;
            st[m++] = Flag;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = mode;
            st[m++] = (byte)updata;
            st[m++] = (byte)(updata >> 8);
            st[m++] = (byte)(updata >> 16);
            st[m++] = (byte)(updata >> 24);
            st[m++] = (byte)lowdata;
            st[m++] = (byte)(lowdata >> 8);
            st[m++] = (byte)(lowdata >> 16);
            st[m++] = (byte)(lowdata >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 站机回执修改空调参数
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="Flag"></param>
        /// <param name="stime"></param>
        /// <returns></returns>
        static public bool RetSendAdjustAirConditon(string DCode, byte Flag, int stime)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x33;
            st[m++] = 0x04;
            st[m++] = Flag;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 终端手动发送空调控制命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="cmdNum"></param>
        /// <param name="li"></param>按照协议组织好的数据
        /// <returns></returns>
        static public bool CmdSendManualoperationAirconditon(string DCode, int cmdNum, List<byte> li)
        {
            byte[] st = new byte[li.Count + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x33;
            st[m++] = 0x05;
            st[m++] = (byte)cmdNum;
            st[m++] = (byte)(cmdNum >> 8);
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 站机发送手动调整空调参数回执
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="cmdNum"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        static public bool RetSendManualoperationAircontion(string DCode, int cmdNum, List<byte> li)
        {
            byte[] st = new byte[li.Count + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x33;
            st[m++] = 0x06;
            st[m++] = (byte)cmdNum;
            st[m++] = (byte)(cmdNum >> 8);
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送获取统计时间
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="stime"></param>
        /// <returns></returns>
        static public bool CmdSendStatisticsTime(string DCode, byte type, int stime)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x19;
            st[m++] = type;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 回执统计信息
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="rNum"></param>
        /// <param name="stime"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        static public bool RetSendStatisticsData(string DCode, byte type, int rNum, int stime, List<byte> li)
        {
            byte[] st = new byte[li.Count + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x19;
            st[m++] = type;
            st[m++] = (byte)rNum;
            st[m++] = (byte)(rNum >> 8);
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 报警实时值发送
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="rNum"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        static public bool AlarmRealtimeValue(string DCode, byte type, int rNum, List<byte> li)
        {
            byte[] st = new byte[li.Count + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x1a;
            st[m++] = type;
            st[m++] = 0x00;
            st[m++] = (byte)rNum;
            st[m++] = (byte)(rNum >> 8);            
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 服务器回执报警信息
        /// </summary>
        /// <returns></returns>
        static public bool RetAlarmRealTimeValue(string DCode ,byte type,int rNum,List<byte>li)
        {
            byte[] st = new byte[li.Count + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x1a;
            st[m++] = type;
            st[m++] = 0x40;
            st[m++] = (byte)rNum;
            st[m++] = (byte)(rNum >> 8);
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送提取设备报警时间列表信息
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="DevType"></param>
        /// <returns></returns>
        static public bool CmdDevAlarmTimeList(string DCode, byte DevType)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x1a;
            st[m++] = DevType;
            st[m++] = 0x40;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 回执设备报警时间列表
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="DevType"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        static public bool RetDevAlarmTimeList(string DCode, byte type, int rNum, List<byte> li)
        {
            byte[] st = new byte[li.Count*4 + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x1a;
            st[m++] = type;
            st[m++] = 0x40;
            st[m++] = (byte)rNum;
            st[m++] = (byte)(rNum >> 8);
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送提取设备报警历史信息命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="DevType"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <returns></returns>
        public static bool CmdDevHistoryAlarm(string DCode, byte DevType, int stime, int etime)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x1a;
            st[m++] = DevType;
            st[m++] = 0x42;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = (byte)etime;
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送报警历史回执信息
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="DevType"></param>
        /// <param name="rNum"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        public static bool RetDevHistoryAlarm(string DCode, byte DevType, int rNum, List<byte> li)
        {
            byte[] st = new byte[li.Count * 4 + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x1a;
            st[m++] = DevType;
            st[m++] = 0x42;
            st[m++] = (byte)rNum;
            st[m++] = (byte)(rNum >> 8);
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送列控实时信息A、B机实时状态
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="ABFlag"></param>
        /// <param name="len"></param>
        /// <param name="stime"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        public static bool SendLK_06HardwareInfo(string DCode, byte ABFlag, int len, int stime, List<byte> li)
        {
            byte[] st = new byte[li.Count + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x1c;
            st[m++] = 0x06;
            st[m++] = 0x00;
            st[m++] = ABFlag;
            st[m++] = (byte)len;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送提取列控时间命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="ABFlag"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool CmdSendLK_06TimeList(string DCode, byte ABFlag, byte type)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x1c;
            st[m++] = 0x06;
            st[m++] = 0x40;
            st[m++] = ABFlag;
            st[m++] = type;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 回执列控提取时间命名
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="ABFlag"></param>
        /// <param name="type"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        public static bool RetSendLK_06TimeList(string DCode, byte ABFlag, byte type, List<int> li)
        {
            byte[] st = new byte[li.Count * 4 + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x1c;
            st[m++] = 0x06;
            st[m++] = 0x40;
            st[m++] = ABFlag;
            st[m++] = type;
            st[m++] = (byte)li.Count;
            st[m++] = (byte)(li.Count >> 8);
            foreach (int key in li)
            {
                st[m++] = (byte)key;
                st[m++] = (byte)(key >> 8);
                st[m++] = (byte)(key >> 16);
                st[m++] = (byte)(key >> 24);
            }
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送提取列控数据命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="ABFlag"></param>
        /// <param name="type"></param>
        /// <param name="stime"></param>
        /// <returns></returns>
        public static bool CmdSendLK_06Data(string DCode, byte ABFlag, byte type, int stime)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x1c;
            st[m++] = 0x06;
            st[m++] = 0x41;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = ABFlag;
            st[m++] = type;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 回执提取列控数据命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="ABFlag"></param>
        /// <param name="type"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        public static bool RetSendLk_06Data(string DCode, byte ABFlag, byte type, List<byte> li)
        {
            byte[] st = new byte[li.Count + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x1c;
            st[m++] = 0x06;
            st[m++] = 0x41;            
            st[m++] = ABFlag;
            st[m++] = type;
            st[m++] = (byte)li.Count;
            st[m++] = (byte)(li.Count >> 8);
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 提取C2列控实时值
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="lkNum"></param>
        /// <param name="ProtecolCode"></param>
        /// <returns></returns>
        public static bool CmdLk_C2RealTimeValue(string DCode, int lkNum, byte ProtecolCode)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x51;
            st[m++] = (byte)lkNum;
            st[m++] = 0x01;
            st[m++] = ProtecolCode;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 回执列控信息实时值
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="lkNum"></param>
        /// <param name="ProtecolCode"></param>
        /// <param name="len"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        public static bool Retlk_c2RealTimeValue(string DCode, int lkNum, byte ProtecolCode,  List<byte> li)
        {
            int len = li.Count;
            byte[] st = new byte[li.Count + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x51;
            st[m++] = (byte)lkNum;
            st[m++] = 0x01;
            st[m++] = ProtecolCode;
            st[m++] = (byte)len;
            st[m++] = (byte)(len >> 8);
            st[m++] = (byte)(len >> 16);
            st[m++] = (byte)(len >> 24);
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送提取列控时间命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="lkNum"></param>
        /// <param name="ProtecolCode"></param>
        /// <returns></returns>
        public static bool CmdLk_C2TimeList(string DCode, int lkNum, byte ProtecolCode)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x51;
            st[m++] = (byte)lkNum;
            st[m++] = 0x40;
            st[m++] = ProtecolCode;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送列控时间列表回执
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="lkNum"></param>
        /// <param name="ProtecolCode"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <returns></returns>
        public static bool RetLk_C2TimeList(string DCode, int lkNum, byte ProtecolCode, int stime, int etime)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x51;
            st[m++] = (byte)lkNum;
            st[m++] = 0x40;
            st[m++] = ProtecolCode;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = (byte)etime;
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送提取列控历史命令数据
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="lkNum"></param>
        /// <param name="ProtecolCode"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <returns></returns>
        public static bool CmdLK_C2History(string DCode, int lkNum, byte ProtecolCode, int stime, int etime)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x51;
            st[m++] = (byte)lkNum;
            st[m++] = 0x41;
            st[m++] = ProtecolCode;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = (byte)etime;
            st[m++] = (byte)(etime >> 8);
            st[m++] = (byte)(etime >> 16);
            st[m++] = (byte)(etime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 回执列控历史信息
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="lkNum"></param> 列控接口数目
        /// <param name="ProtecolCode"></param> 列控协议版本
        /// <param name="stime"></param> 时间
        /// <param name="rNum"></param> 记录条数
        /// <param name="li"></param>未压缩前数据
        /// <returns></returns>
        public static bool RetLk_C2HistoryData(string DCode, int lkNum, byte ProtecolCode, int stime, int rNum, List<byte> li)
        {
            byte[] st = new byte[li.Count+100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;     //数据，协议中写错
            st[m++] = 0x01;     //内存压缩，协议中写错
            st[m++] = 0xe0;
            st[m++] = 0x51;
            st[m++] = (byte)lkNum;
            st[m++] = 0x41;
            st[m++] = ProtecolCode;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = (byte)rNum;
            st[m++] = (byte)(rNum >> 8);
            int RarSize = (int)compressBound((uint)li.Count);   //得到压缩后的长度
            byte[] t = new byte[RarSize];
            int r = zCompress(li.ToArray(), li.Count, t, ref RarSize, 1);   //使用内存压缩
            if (r == Z_OK)
            {
                Array.Copy(t, 0, st, m, RarSize);
                m += RarSize;
                st[m++] = 0xff;
                return SendNetComData(0x0f, st, m);
            }
            else return false;
        }
        /// <summary>
        /// 站机主动上传配置文件
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="li"></param>压缩前的配置文件格式.
        /// <returns></returns>
        public static bool SendCfgFile(string DCode, List<byte> li)
        {
            byte[] st = new byte[li.Count + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x52;
            st[m++] = 0x02;
            int RarSize = (int)compressBound((uint)li.Count);   //得到压缩后的长度
            byte[] t = new byte[RarSize];
            int r = zCompress(li.ToArray(), li.Count, t, ref RarSize, 1);   //使用内存压缩
            if (r == Z_OK)
            {
                Array.Copy(t, 0, st, m, RarSize);
                m += RarSize;
                st[m++] = 0xff;
                return SendNetComData(0x0f, st, m);
            }
            else return false;
        }
        /// <summary>
        /// 发送提取配置文件命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <returns></returns>
        public static bool CmdExtractCfgFile(string DCode)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x52;
            st[m++] = 0x02;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 主动上送系统状态信息
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="SonType"></param>
        /// <param name="rNum"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        public static bool SendSysStatueInfo(string DCode, byte SonType, int rNum, List<byte> li)
        {
            byte[] st = new byte[li.Count + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x1d;
            st[m++] = SonType;
            st[m++] = (byte)rNum;
            st[m++] = (byte)(rNum >> 8);
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送提取系统状态信息命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="SonType"></param>
        /// <returns></returns>
        public static bool CmdExtractSysStatue(string DCode, byte SonType)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x1d;
            st[m++] = SonType;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送提取系统工作日志时间列表命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static bool CmdExtractLogTimeList(string DCode, byte type)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x1e;
            st[m++] = type;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 回执系统日志信息时间列表
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        public static bool RetSendLogTimeList(string DCode, byte type, List<int> li)
        {
            byte[] st = new byte[li.Count * 4 + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x1e;
            st[m++] = type;
            st[m++] = 0x40;
            st[m++] = (byte)li.Count;
            st[m++] = (byte)(li.Count >> 8);
            foreach (int key in li)
            {
                st[m++] = (byte)key;
                st[m++] = (byte)(key >> 8);
                st[m++] = (byte)(key >> 16);
                st[m++] = (byte)(key >> 24);
            }
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 提取系统历史日志数据命令
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="stime"></param>
        /// <returns></returns>
        public static bool CmdLogHistoryData(string DCode, byte type, int stime)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x01;
            st[m++] = 0xe0;
            st[m++] = 0x1e;            
            st[m++] = type;
            st[m++] = 0x41;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 回执系统日志历史信息
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="type"></param>
        /// <param name="rNum"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        public static bool RetLogHistoryData(string DCode, byte type, int rNum, List<byte> li)
        {
            byte[] st = new byte[li.Count + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x1e;
            st[m++] = type;
            st[m++] = 0x41;
            st[m++] = (byte)rNum;
            st[m++] = (byte)(rNum >> 8);
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 公司特色功能
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="DCFlag"></param>
        /// <param name="VerFlag"></param>
        /// <param name="type"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        public static bool CorporationSpecificCmd(string DCode, byte DCFlag, byte VerFlag, byte type, List<byte> li)
        {
            byte[] st = new byte[li.Count + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = DCFlag;   //数据、命令标志
            st[m++] = VerFlag;
            st[m++] = 0x40;
            st[m++] = type;
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送网络状态信息
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="li"></param>
        /// <returns></returns>
        public static bool SendNetStatue(string DCode, List<byte> li)
        {
            byte[] st = new byte[li.Count + 100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe1;
            st[m++] = 0x23;
            st[m++] = (byte)li.Count;
            st[m++] = (byte)(li.Count >> 8);
            st[m++] = (byte)(li.Count >> 16);
            st[m++] = (byte)(li.Count >> 24);
            Array.Copy(li.ToArray(), 0, st, m, li.Count);
            m += li.Count;
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
        /// <summary>
        /// 发送站机启动信息
        /// </summary>
        /// <param name="DCode"></param>
        /// <param name="stime"></param>
        /// <returns></returns>
        public static bool SendStationPowerup(string DCode,int stime)
        {
            byte[] st = new byte[100];
            SetTeleCode(st, DCode);
            int m = 6;
            st[m++] = 0x00;
            st[m++] = 0x00;
            st[m++] = 0xe0;
            st[m++] = 0x1f;
            st[m++] = 0x00;
            st[m++] = (byte)stime;
            st[m++] = (byte)(stime >> 8);
            st[m++] = (byte)(stime >> 16);
            st[m++] = (byte)(stime >> 24);
            st[m++] = 0xff;
            return SendNetComData(0x0f, st, m);
        }
    }
}
